﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using log4net;

namespace BizzUI
{
    public partial class LoginWindow : Form
    {
        private static readonly ILog auditLog =
                      LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public LoginWindow()
        {
            InitializeComponent();
            log4net.Config.XmlConfigurator.Configure();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBoxUser.Text == "") textBoxUser.Text = "Operator";
            BizzCommMainForm mainForm = null;
            if (textBoxUser.Text == "admin")
                mainForm = new BizzCommMainForm("admin");
            else
                mainForm = new BizzCommMainForm(textBoxUser.Text);
            try
            {
                auditLog.Info(textBoxUser.Text + " ha iniciado sesión");

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show("No es posible conectar a la base de datos. Por favor revise la configuración");
                
            }
            mainForm.FormClosed += new FormClosedEventHandler(mainForm_FormClosed);
            mainForm.Show();
            this.Hide();
        }

        void mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
        }
    }
}
